package main

import (
	"fmt"
)

// 函数式编程, 闭包
func main() {
	f := adder()(12)
	fmt.Printf("%d\n", f)

	add := adder2(3)

	i, i2 := add(12)
	fmt.Println(i)
	i3, _ := i2(13)
	fmt.Println(i3)

}

func adder() func(int) int {
	sum := 1
	return func(val int) int {
		return sum + val
	}
}

type iAdder func(int) (int, iAdder)

func adder2(base int) iAdder {
	return func(v int) (int, iAdder) {
		return base + v, adder2(base + v)
	}
}
